package com.modern.model;

import com.modern.model.BaseObject;

import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;

import java.io.Serializable;

@Entity
@Table(name="question",catalog="typing")
public class Question extends BaseObject implements Serializable {
    private Long questionId;
    private String questionContent;
    private String questionTitle;
    private Set<Paper> papers = new HashSet<Paper>(0);

    @Id @GeneratedValue(strategy=IDENTITY)     
    public Long getQuestionId() {
        return this.questionId;
    }
    
    public void setQuestionId(Long questionId) {
        this.questionId = questionId;
    }
    
    @Column(name="questionContent", length=7000)
    public String getQuestionContent() {
        return this.questionContent;
    }
    
    public void setQuestionContent(String questionContent) {
        this.questionContent = questionContent;
    }
    
    @Column(name="questionTitle", length=50)
    public String getQuestionTitle() {
        return this.questionTitle;
    }
    
    public void setQuestionTitle(String questionTitle) {
        this.questionTitle = questionTitle;
    }
@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="question")
    public Set<Paper> getPapers() {
        return this.papers;
    }
    
    public void setPapers(Set<Paper> papers) {
        this.papers = papers;
    }

    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Question pojo = (Question) o;

        if (questionContent != null ? !questionContent.equals(pojo.questionContent) : pojo.questionContent != null) return false;
        if (questionTitle != null ? !questionTitle.equals(pojo.questionTitle) : pojo.questionTitle != null) return false;

        return true;
    }

    public int hashCode() {
        int result = 0;
        result = (questionContent != null ? questionContent.hashCode() : 0);
        result = 31 * result + (questionTitle != null ? questionTitle.hashCode() : 0);

        return result;
    }

    public String toString() {
        StringBuffer sb = new StringBuffer(getClass().getSimpleName());

        sb.append(" [");
        sb.append("questionId").append("='").append(getQuestionId()).append("', ");
        sb.append("questionContent").append("='").append(getQuestionContent()).append("', ");
        sb.append("questionTitle").append("='").append(getQuestionTitle()).append("', ");
        
        sb.append("]");
      
        return sb.toString();
    }

}
